package br.com.ac.fatureweb.utilitary;

import java.io.Serializable;

import javax.persistence.Inheritance;
import javax.persistence.MappedSuperclass;

/**
 * 
 * Standard model that will be inherited by all entities.
 *
 */
@Inheritance
@MappedSuperclass
public abstract class Model implements Serializable {

	private static final long serialVersionUID = -4472197553236487901L;

	/**
	 * 
	 * @return
	 */
	public Long getId() {
		return FacesUtils.getPropertyIdValue(this);
	}

	/**
	 * 
	 * @param id
	 */
	public void setId(Long id) {
		FacesUtils.setPropertyIdValue(this, id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Model other = (Model) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		if (getId() != null) {
			return getId().toString();
		}
		return null;
	}

}